home *** CD-ROM | disk | FTP | other *** search
- {$A+,B-,D+,E+,F-,I+,L+,N-,O-,R-,S+,V-}
- {$M 1024,0,655360}
-
- { *********************************************************************** }
- { TRANSLATE }
- { }
- { Copyright 1990 by Gil Yoder }
- { P.O. Box 307 }
- { Coalgate, OK 74538 }
- { }
- { CIS: 73237,3103 }
- { }
- { You may use, copy, distribute, and modify TRANSLATE without restriction }
- { but you may not sell TRANSLATE or programs derived herefrom. If you do }
- { modify the program, the author of TRANSLATE would appreciate notifica- }
- { tion. }
- { *********************************************************************** }
- { TRANSLATE is a simple keyboard redefinition program that gives the user }
- { the ability to translate five keys on the IBM enhanced keyboard to any }
- { keys of his choice. The user must know the word value of the key he }
- { wishes to translate, and the word value for the key to which it should }
- { be translated. These values can be discovered with KEYWORD. }
- { }
- { TRANSLATE takes the following syntax: }
- { }
- { TRANSLAT oldkey1 newkey1 [oldkey2 newkey2] ... [oldkey5 newkey5] }
- { }
- { Both oldkey and newkey should be entered as #### where each # may be }
- { of these characters: 0123456789ABCDEF. Obviously the values are }
- { hexadecimal. All four characters should be filled, so if you have a }
- { key with a value less than 1000h, you should pad the first digit(s) }
- { with a zero (0). Lower case characters are not allowed. There must be }
- { at least one oldkey newkey pair, and may not be more than 5 pairs. }
- { Each oldkey parameter must be matched by a newkey parameter. If }
- { TRANSLATE detects any errors it will not be installed, and an audible }
- { beep will sound. }
- { }
- { If TRANSLATE is successfully installed, it will watch for keys from the }
- { keyboard matching each oldkey, and replace its value with the }
- { corresponding newkey. }
- { *********************************************************************** }
- { TRANSLATE requires Turbo Professional Toolbox from Turbo Power in order }
- { for it to be recompiled. }
- { *********************************************************************** }
-
-
-
- program translate;
- uses tpint,tptsr;
-
- type
- str5 = string[5];
-
- var
- Index : byte;
- WordsToTrans : array[1..10] of word;
- NumberOfWords : byte;
-
- procedure TranslateIsr(BP : word); interrupt;
- var
- Regs : IntRegisters absolute BP;
- begin
- if (regs.ah = 0) or (regs.ah = $10) then begin
- { Call old interrupt to get key into ax }
- EmulateInt(Regs, ISR_Array[16].OrigAddr);
- index := 255; { Same as -1, for a byte }
- repeat
- inc(index,2);
- if WordsToTrans[index] = regs.ax then { If the key in the table, }
- regs.ax := WordsToTrans[index+1] { translate it }
- until (index = NumberOfWords);
- end else
- { Call old interrupt to perform other functions }
- ChainInt(Regs, ISR_Array[16].OrigAddr);
- end;
-
- function HexToWord(s : str5; var w : word) : boolean;
- var
- i : byte;
- begin
- HexToWord := false; { Assume failure }
-
- if s[0] <> #4 then { String must be 4 chars long }
- exit;
-
- w := 0;
- for i := 1 to 4 do begin
- w := w * 16;
- case s[i] of
- '0'..'9' : w := w + ord(s[i]) - ord('0');
- 'A'..'F' : w := w + ord(s[i]) - ord('A') + 10;
- else
- exit;
- end;
- end;
- HexToWord := true;
- end;
-
- procedure error(x : byte); { General purpose Error handler }
- begin
- write(char(7));
- halt(x);
- end;
- { Main routine to set up TSR }
- begin
- if (ParamCount mod 2 = 1) then
- error(1) { Odd number of parameters }
- else if (ParamCount = 0) then
- error(2) { No parameters }
- else if (ParamCount > 10) then
- error(3); { Too many parameters }
-
- for Index := 1 to ParamCount do
- if not HexToWord(ParamStr(Index),WordsToTrans[Index]) then
- error(4); { Parameter improperly formed }
-
- NumberOfWords := ParamCount - 1;
-
- if not InitVector($16,16,@TranslateIsr) then;
- { error(5) { Only if handle (16) improper. Impossible error. }
- if not TerminateAndStayResident(ParagraphsToKeep, 0) then
- error(6); { Un able to release program's memory }
-
- end.